package com.xb.report.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xb.report.mapper.DataCountMapper;
import com.xb.report.service.IDataCountService;
import com.xb.report.util.Constants;
import com.xb.report.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author gxd
 * @Date： 2018/6/12
 */
@Service
public class DataCountService implements IDataCountService {

    @Autowired
    private DataCountMapper dataCountMapper;

    @Override
    public List<Map<String, Object>> getViewsList(String startDate, String endDate,String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }


        return dataCountMapper.getViewsList(map);
    }
    @Override
    public List<Map<String, Object>> getVisitList(String startDate, String endDate) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        return dataCountMapper.getVisitList(map);
    }


    @Override
    public List<Map<String, Object>> getNumList(String startDate, String endDate,String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getNumList(map);

    }

    @Override
    public List<Map<String, Object>> getDedctionList(String startDate, String endDate,String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getDedctionList(map);

    }
    @Override
    public List<Map<String, Object>> getPayList(String startDate, String endDate,String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getPayList(map);

    }

    @Override
    public List<Map<String, Object>> getProfitList(String startDate, String endDate,String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getProfitList(map);

    }

    @Override
    public List<Map<String, Object>> getUidTop10(String planid,String adsid,String advuid, String startDate, String endDate, String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(planid)) {
            map.put("planid", planid);
        }
        if (Tools.notEmpty(adsid)) {
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(advuid)) {
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getUidTop10(map);

    }


    @Override
    public List<Map<String, Object>> getPlanTop10(String uid, String startDate, String endDate, String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(uid)) {
            map.put("uid", uid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getPlanTop10(map);

    }

    @Override
    public List<Map<String, Object>> getAdvTop10(String zoneid, String startDate, String endDate, String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(zoneid)) {
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getAdvTop10(map);

    }

    @Override
    public List<Map<String, Object>> getSiteTop10(String advuid, String startDate, String endDate, String planType){
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(advuid)) {
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getSiteTop10(map);

    }


    @Override
    public Page<Map<String, Object>> getPlanListByPage(String planId, String planType, String sort, String startDate, String endDate, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        String sname="";

        //默认 浏览数
        if("1".equals(sort)){
            sname="CAST(day AS DATE) desc,CAST(views AS signed) DESC";
        }else if("2".equals(sort)){
            sname="CAST(views AS DECIMAL) DESC";
        }else if("3".equals(sort)){
            sname="CAST(num AS DECIMAL) DESC";
        }else if("4".equals(sort)){
            sname="CAST(crt AS DECIMAL) DESC";
        }else if("5".equals(sort)){
            sname="CAST(cparate AS DECIMAL) DESC";
        }else if("6".equals(sort)){
            sname="CAST(sumadvpay AS DECIMAL) DESC";
        }else if("7".equals(sort)){
            sname="CAST(sumprofit AS DECIMAL) DESC";
        }else{
            sname="CAST(views AS DECIMAL) DESC";
        }

        Map<String, String> map = new HashMap<String, String>();
        map.put("sname", sname);

        if (Tools.notEmpty(planId)) {
            map.put("planId", planId);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }

        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        return dataCountMapper.getPlanListByPage(map);

    }



    @Override
    public List<Map<String, Object>> getBrowserList(String startDate, String endDate) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }


        return dataCountMapper.getBrowserList(map);

    }


    @Override
    public List<Map<String, Object>> getAreaListList(String startDate, String endDate){
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        List<Map<String, Object>> areaList=dataCountMapper.getAreaList(map);
        //todo  id字段待修改
        for(Map map1 : areaList){
            String name=changeCodeToName(Constants.provinceMap,map1.get("id").toString());
            map1.put("name",name);

        }

        return areaList;

    }

    @Override
    public List<Map<String, Object>> getIspListList(String startDate, String endDate){
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        List<Map<String, Object>> ispList=dataCountMapper.getIspListList(map);
        //todo  id字段待修改getIspListByids
        for(Map map1 : ispList){
            String name=changeCodeToName(Constants.ispMap,map1.get("id").toString());
            map1.put("name",name);

        }
        return ispList;

    }

    @Override
    public List<Map<String, Object>> getPhoneBrandList(String startDate, String endDate) {
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }


        return dataCountMapper.getPhoneBrandList(map);
    }

    @Override
    public List<Map<String, Object>> getPlanAdvTop10(String planid, String uid, String zoneid, String startDate, String endDate, String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();
        if (Tools.notEmpty(planid)) {
            map.put("planid", planid);
        }
        if (Tools.notEmpty(uid)) {
            map.put("uid", uid);
        }
        if (Tools.notEmpty(zoneid)) {
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getPlanAdvTop10(map);
    }

    @Override
    public List<Map<String, Object>> getZoneTop10(String planid, String uid, String adsid, String startDate, String endDate, String planType) throws Exception{
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(planid)) {
            map.put("planid", planid);
        }
        if (Tools.notEmpty(uid)) {
            map.put("uid", uid);
        }
        if (Tools.notEmpty(adsid)) {
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }

        return dataCountMapper.getZoneTop10(map);

    }

    @Override
    public Page<Map<String, Object>> getUidListByPage(String uid, String planType, String sort, String startDate, String endDate, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        String sname="";


        //默认 浏览数
        if("1".equals(sort)){
            sname="CAST(day AS DATE) desc,CAST(views AS signed) DESC";
        }else if("2".equals(sort)){
            sname="CAST(views AS DECIMAL) DESC";
        }else if("3".equals(sort)){
            sname="CAST(num AS DECIMAL) DESC";
        }else if("4".equals(sort)){
            sname="CAST(crt AS DECIMAL) DESC";
        }else if("5".equals(sort)){
            sname="CAST(cparate AS DECIMAL) DESC";
        }else if("6".equals(sort)){
            sname="CAST(sumpay AS DECIMAL) DESC";
        }else if("7".equals(sort)){
            sname="CAST(sumprofit AS DECIMAL) DESC";
        }else{
            sname="CAST(views AS DECIMAL) DESC";
        }


        Map<String, String> map = new HashMap<String, String>();
        map.put("sname", sname);

        if (Tools.notEmpty(uid)) {
            map.put("uid", uid);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }

        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        return dataCountMapper.getUidListByPage(map);

    }

    @Override
    public List<Map<String, Object>> getSumUidList(String uid, String planType, String startDate, String endDate) {
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(uid)) {
            map.put("uid", uid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getSumUidList(map);

    }
    @Override
    public List<Map<String, Object>> getSumPlanList(String planId, String planType, String startDate, String endDate) {
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(planId)) {
            map.put("planId", planId);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getSumPlanList(map);

    }


    @Override
    public Page<Map<String, Object>> getAdsIdListByPage(String adsid, String planType, String sort, String startDate, String endDate, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        String sname="";


        //默认 浏览数
        if("1".equals(sort)){
            sname="CAST(day AS DATE) desc,CAST(views AS signed) DESC";
        }else if("2".equals(sort)){
            sname="CAST(views AS DECIMAL) DESC";
        }else if("3".equals(sort)){
            sname="CAST(num AS DECIMAL) DESC";
        }else if("4".equals(sort)){
            sname="CAST(crt AS DECIMAL) DESC";
        }else if("5".equals(sort)){
            sname="CAST(cparate AS DECIMAL) DESC";
        }else if("6".equals(sort)){
            sname="CAST(sumpay AS DECIMAL) DESC";
        }else if("7".equals(sort)){
            sname="CAST(sumprofit AS DECIMAL) DESC";
        }else{
            sname="CAST(views AS DECIMAL) DESC";
        }


        Map<String, String> map = new HashMap<String, String>();
        map.put("sname", sname);

        if (Tools.notEmpty(adsid)) {
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }

        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        return dataCountMapper.getAdsIdListByPage(map);

    }

    @Override
    public List<Map<String, Object>> getSumAdsIdList(String adsid, String planType, String startDate, String endDate) {
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(adsid)) {
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getSumAdsIdList(map);

    }


    @Override
    public Page<Map<String, Object>> getZoneIdListByPage(String zoneid, String planType, String sort, String startDate, String endDate, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        String sname="";


        //默认 浏览数
        if("1".equals(sort)){
            sname="CAST(day AS DATE) desc,CAST(views AS signed) DESC";
        }else if("2".equals(sort)){
            sname="CAST(views AS DECIMAL) DESC";
        }else if("3".equals(sort)){
            sname="CAST(num AS DECIMAL) DESC";
        }else if("4".equals(sort)){
            sname="CAST(crt AS DECIMAL) DESC";
        }else if("5".equals(sort)){
            sname="CAST(cparate AS DECIMAL) DESC";
        }else if("6".equals(sort)){
            sname="CAST(sumpay AS DECIMAL) DESC";
        }else if("7".equals(sort)){
            sname="CAST(sumprofit AS DECIMAL) DESC";
        }else{
            sname="CAST(views AS DECIMAL) DESC";
        }


        Map<String, String> map = new HashMap<String, String>();
        map.put("sname", sname);

        if (Tools.notEmpty(zoneid)) {
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }

        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        return dataCountMapper.getZoneIdListByPage(map);

    }


    @Override
    public List<Map<String, Object>> getSumZoneIdList(String zoneid, String planType, String startDate, String endDate) {
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(zoneid)) {
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getSumZoneIdList(map);

    }


    @Override
    public Page<Map<String, Object>> getAdvUidListByPage(String advuid, String planType, String sort, String startDate, String endDate, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        String sname="";

        //默认 浏览数
        if("1".equals(sort)){
            sname="CAST(day AS DATE) desc,CAST(views AS signed) DESC";
        }else if("2".equals(sort)){
            sname="CAST(views AS DECIMAL) DESC";
        }else if("3".equals(sort)){
            sname="CAST(num AS DECIMAL) DESC";
        }else if("4".equals(sort)){
            sname="CAST(crt AS DECIMAL) DESC";
        }else if("5".equals(sort)){
            sname="CAST(cparate AS DECIMAL) DESC";
        }else if("6".equals(sort)){
            sname="CAST(sumadvpay AS DECIMAL) DESC";
        }else if("7".equals(sort)){
            sname="CAST(sumprofit AS DECIMAL) DESC";
        }else{
            sname="CAST(views AS DECIMAL) DESC";
        }



        Map<String, String> map = new HashMap<String, String>();
        map.put("sname", sname);

        if (Tools.notEmpty(advuid)) {
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }

        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        return dataCountMapper.getAdvUidListByPage(map);

    }


    @Override
    public List<Map<String, Object>> getSumAdvUidList(String advuid, String planType, String startDate, String endDate) {
        Map<String, String> map = new HashMap<String, String>();

        if (Tools.notEmpty(advuid)) {
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return dataCountMapper.getSumAdvUidList(map);

    }


    /* 从result表中获取结算top10   */
    public List<Map<String, Object>> getUidTopFromResult(String startDate, String endDate, String planType)
            throws Exception
    {
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return this.dataCountMapper.getUidTopFromResult(map);
    }

    public List<Map<String, Object>> getPlanTopFromResult(String startDate, String endDate, String planType)
            throws Exception
    {
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return this.dataCountMapper.getPlanTopFromResult(map);
    }

    public List<Map<String, Object>> getAdvTopFromResult(String startDate, String endDate, String planType)
            throws Exception
    {
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return this.dataCountMapper.getAdvTopFromResult(map);
    }

    public List<Map<String, Object>> getSiteTopFromResult(String startDate, String endDate, String planType)
    {
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return this.dataCountMapper.getSiteTopFromResult(map);
    }



    public List<Map<String, Object>> getPlanAdvTopFromResult(String startDate, String endDate, String planType)
            throws Exception
    {
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return this.dataCountMapper.getPlanAdvTopFromResult(map);
    }

    public List<Map<String, Object>> getZoneTopFromResult(String startDate, String endDate, String planType)
            throws Exception
    {
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        if (Tools.notEmpty(planType)) {
            map.put("planType", planType);
        }
        return this.dataCountMapper.getZoneTopFromResult(map);
    }


    @Override
    public List<Map<String, Object>> getPhoneBrandListByids(String planid, String uid, String adsid, String zoneid, String advuid, String startDate, String endDate) {
        Map<String, String> map = new HashMap();
        String table="";
        if (Tools.notEmpty(planid)) {
            table="result_planid_mobile";
            map.put("planid", planid);
        }
        if (Tools.notEmpty(uid)) {
            table="result_uid_mobile";
            map.put("uid", uid);
        }
        if (Tools.notEmpty(adsid)) {
            table="result_adsid_mobile";
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(zoneid)) {
            table="result_zoneid_mobile";
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(advuid)) {
            table="result_advuid_mobile";
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        map.put("table",table);

        return this.dataCountMapper.getPhoneBrandListByids(map);
    }
    @Override
    public List<Map<String, Object>> getBrowserListByids(String planid, String uid, String adsid, String zoneid, String advuid, String startDate, String endDate) {
        Map<String, String> map = new HashMap();
        String table="";
        if (Tools.notEmpty(planid)) {
            table="result_planid_browser";
            map.put("planid", planid);
        }
        if (Tools.notEmpty(uid)) {
            table="result_uid_browser";
            map.put("uid", uid);
        }
        if (Tools.notEmpty(adsid)) {
            table="result_adsid_browser";
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(zoneid)) {
            table="result_zoneid_browser";
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(advuid)) {
            table="result_advuid_browser";
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        map.put("table",table);

        return this.dataCountMapper.getBrowserListByids(map);
    }


    @Override
    public List<Map<String, Object>> getIspListByids(String planid, String uid, String adsid, String zoneid, String advuid, String startDate, String endDate) {
        String table="";
        Map<String, String> map = new HashMap();
        if (Tools.notEmpty(planid)) {
            table="result_planid_isp";
            map.put("planid", planid);
        }
        if (Tools.notEmpty(uid)) {
            table="result_uid_isp";
            map.put("uid", uid);
        }
        if (Tools.notEmpty(adsid)) {
            table="result_adsid_isp";
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(zoneid)) {
            table="result_zoneid_isp";
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(advuid)) {
            table="result_advuid_isp";
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        map.put("table",table);

        List<Map<String, Object>> ispList=dataCountMapper.getIspListByids(map);
        //todo  id字段待修改getIspListByids
        for(Map map1 : ispList){
            String name=changeCodeToName(Constants.ispMap,map1.get("id").toString());
            map1.put("name",name);

        }
        return ispList;
    }
    @Override
    public List<Map<String, Object>> getAreaListByids(String planid, String uid, String adsid, String zoneid, String advuid, String startDate, String endDate) {
        Map<String, String> map = new HashMap();
        String table="";
        if (Tools.notEmpty(planid)) {
            table="result_planid_region";
            map.put("planid", planid);
        }
        if (Tools.notEmpty(uid)) {
            table="result_uid_region";
            map.put("uid", uid);
        }
        if (Tools.notEmpty(adsid)) {
            table="result_adsid_region";
            map.put("adsid", adsid);
        }
        if (Tools.notEmpty(zoneid)) {
            table="result_zoneid_region";
            map.put("zoneid", zoneid);
        }
        if (Tools.notEmpty(advuid)) {
            table="result_advuid_region";
            map.put("advuid", advuid);
        }
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }
        map.put("table",table);
        List<Map<String, Object>> areaList=dataCountMapper.getAreaListByids(map);
        for(Map map1 : areaList){
            String name=changeCodeToName(Constants.provinceMap,map1.get("id").toString());
            map1.put("name",name);

        }
        return areaList;
    }




    /**
     * code转化为name
     * @param map
     * @param code
     * @return
     */
    private String changeCodeToName(Map<String, String> map, String code){

        String name = map.get(code).toString();

        return name;
    }




    //===========================分析相关===============================
    @Override
    public List<Map<String, Object>> getDaBrowser(String startDate, String endDate,String type){
        Map<String, String> map = new HashMap<String, String>();
        map.put("type",type);
        if (Tools.notEmpty(startDate)) {
            map.put("startDate", startDate);
        }
        if (Tools.notEmpty(endDate)) {
            map.put("endDate", endDate);
        }

        return dataCountMapper.getDaBrowser(map);

    }
}
